// pages/component-pages/scroll-view/scroll-view.js
var order = ['green', 'red', 'yellow', 'blue', 'green']

Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop: 0,
    toView: 'green'
  },


  scroll(e) {
    const { scrollTop } = e.detail
    this.setData({ scrollTop })
  },
  addScrollTop(e) {
    const { num } = e.currentTarget.dataset
    this.setData({ scrollTop: this.data.scrollTop += num })
  },
  scroll2View(e) {
    for (var i = 0; i < order.length; ++i) {
      if (order[i] === this.data.toView) {
        this.setData({
          toView: order[i + 1],
        })
        break
      }
    }
  },
  scroll2Top(e) {
    this.setData({
      scrollTop: 0
    })
  }
})